import React from 'react';
import { Table, Tag, Pagination } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { TableItem, PaginationParams } from '../types';
import { STATUS_CLASS_MAP } from '../constants';
import style from './index.less';


interface DataTableProps {
  data: TableItem[];
  loading: boolean;
  pagination: PaginationParams;
  onPageChange: (page: number, pageSize?: number) => void;
}

const DataTable: React.FC<DataTableProps> = ({ 
  data, 
  loading, 
  pagination, 
  onPageChange 
}) => {
  const columns: ColumnsType<TableItem> = [
    { title: '投产规划编号', dataIndex: 'id', key: 'id' },
    { title: '投产规划名称', dataIndex: 'name', key: 'name' },
    { title: '申报中心', dataIndex: 'center', key: 'center' },
    { title: '投产计划实施时间', dataIndex: 'period', key: 'period' },
    { title: '提交人', dataIndex: 'submitter', key: 'submitter' },
    { title: '规划提审时间', dataIndex: 'submitTime', key: 'submitTime' },
    { title: '审批通过时间', dataIndex: 'approveTime', key: 'approveTime' },
    {
      title: '投产规划状态',
      dataIndex: 'status',
      key: 'status',
      render: (status: string) => {
        const className = STATUS_CLASS_MAP[status as keyof typeof STATUS_CLASS_MAP] || 'status-grey';
        return <Tag className={className}>{status}</Tag>;
      }
    },
    {
      title: '操作',
      key: 'action',
      render: () => (
        <a className="operation-link">查看</a>
      ),
    },
  ];

  return (
    <div className={style['table-container']}>
      <Table
        columns={columns}
        dataSource={data}
        rowKey="id"
        loading={loading}
        className="data-table"
        pagination={false}
      />
      <div className={style['pagination-wrapper']}>
        <span className={style['total-count']}>共{pagination.total}条</span>
        <Pagination
          current={pagination.current}
          pageSize={pagination.pageSize}
          total={pagination.total}
          onChange={onPageChange}
          showSizeChanger={false}
        />
      </div>
    </div>
  );
};

export default DataTable; 